package day04;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

/**
 * 创建一个集合，存放元素"1","$","2","$","3","$","4"
 *   使用迭代器遍历集合，并在过程中删除所有的"$"，
 *   最后再将删除元素后的集合使用新循环遍历，并输出每一个元素。
 * @author Bonnie
 *
 */
public class Test02 {
    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();
        Collections.addAll(list,"1","$","2","$","3","$","4");
        Iterator<Object> iterator = list.iterator();
        while (iterator.hasNext()){
            Object next = iterator.next();
            if(next=="$"){
                iterator.remove();
            }
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
